package com.yanqu.road.dao.impl.activity.sonhai;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.daomu.config.DaoMuNpcConfig;
import com.yanqu.road.entity.activity.sonhai.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class SonHaiConfigDaoImpl extends TempDao {

    /**
     * 事件配置表
     */
    public Map<Integer, SonHaiEventConfig> getEventConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_event` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiEventConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiEventConfig config = new SonHaiEventConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setIcon(rs.getInt("icon"));
                config.setEventType(rs.getInt("eventType"));
                config.setName(rs.getString("name"));
                config.setMonster(rs.getString("monster"));
                config.setEventDesc(rs.getString("eventDesc"));
                config.setDesc(rs.getString("desc"));
                config.setSimpleDesc(rs.getString("simpleDesc"));
                config.setLevel(rs.getInt("level"));
                config.setParam(rs.getString("param"));
                config.setReward(rs.getString("reward"));
                config.setSchedule(rs.getInt("schedule"));
                config.setMonsterScore(rs.getLong("monsterScore"));
                config.setPvpScore(rs.getLong("pvpScore"));
                config.setChooseReward(rs.getString("chooseReward"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 区域配置表
     */
    public Map<Integer, SonHaiFloorConfig> getFloorConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_floor` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiFloorConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiFloorConfig config = new SonHaiFloorConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setFloor(rs.getInt("floor"));
                config.setName(rs.getString("name"));
                config.setEnergy(rs.getInt("energy"));
                config.setNeedSchedule(rs.getInt("needSchedule"));
                config.setSpecial(rs.getInt("special"));
                config.setEventWeight(rs.getString("eventWeight"));
                config.setEventNum(rs.getString("eventNum"));
                config.setBuffWeight(rs.getString("buffWeight"));
                config.setMonsterHpAdd(rs.getInt("monsterHpAdd"));
                config.setPower(rs.getInt("power"));
                config.setBuffNum(rs.getInt("buffNum"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * BUFF配置表
     */
    public Map<Integer, SonHaiBuffConfig> getBuffConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_buff` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiBuffConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiBuffConfig config = new SonHaiBuffConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setIcon(rs.getInt("icon"));
                config.setBuffType(rs.getInt("buffType"));
                config.setName(rs.getString("name"));
                config.setDesc(rs.getString("desc"));
                config.setLevel(rs.getInt("level"));
                config.setParam(rs.getString("param"));
                config.setUpgradeParam(rs.getString("upgradeParam"));
                config.setNum(rs.getInt("num"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 怪配置表
     */
    public Map<Integer, SonHaiMonsterConfig> getMonsterConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_monster` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiMonsterConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiMonsterConfig config = new SonHaiMonsterConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setIcon(rs.getInt("icon"));
                config.setName(rs.getString("name"));
                config.setDesc(rs.getString("desc"));
                config.setParam(rs.getString("param"));
                config.setLevel(rs.getInt("level"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 蛋置表
     */
    public Map<Integer, SonHaiEggConfig> getEggConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_egg` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiEggConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiEggConfig config = new SonHaiEggConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setIcon(rs.getInt("icon"));
                config.setName(rs.getString("name"));
                config.setMonster(rs.getString("monster"));
                config.setEventDesc(rs.getString("eventDesc"));
                config.setDesc(rs.getString("desc"));
                config.setLevel(rs.getInt("level"));
                config.setParam(rs.getString("param"));
                config.setWeight(rs.getInt("weight"));
                config.setReward(rs.getString("reward"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 地图表
     */
    public Map<Integer, SonHaiMapConfig> getMapConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_map` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiMapConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiMapConfig config = new SonHaiMapConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setFloor(rs.getInt("floor"));
                config.setParam(rs.getString("param"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }


    /**
     * 蛋名表
     */
    public Map<Integer, SonHaiEggNameConfig> getEggNameConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_sonhai_egg_name` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, SonHaiEggNameConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SonHaiEggNameConfig config = new SonHaiEggNameConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setName(rs.getString("name"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
